package com.example.graduation.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * ProjectName graduation
 *
 * @author xieyucan
 * <br>CreateDate 2022/2/12 10:19
 */
public class PhoneOrEmailUtil {

    /**
     * 验证是否为手机号
     *
     * @param number
     * @return
     */
    public static boolean isPhone(String number) {
        String reg = "^((13[0-9])|(14[5-7])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(number);
        return matcher.matches();
    }

    /**
     * 验证是否为邮箱号码
     *
     * @param number
     * @return
     */
    public static boolean isEmail(String number) {
        String reg = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(number);
        return matcher.matches();
    }
}
